function openBg(state){ //打开关闭控制
	 if(state == 1){
	  $("#bg").css('display', 'block');
	  var h = document.body.offsetHeight > document.documentElement.offsetHeight ? document.body.offsetHeight : document.documentElement.offsetHeight;
	 $("#bg").css('height', h + "px");
	 } else {
	  $("#bg").css('display', 'none');
	 } 
}
	function openSelect(state){ //选择推荐类型层关闭打开控制
	 if(state == 1) {
	  $("#selectItem").css('display', 'block');
	  $("#selectItem").css('left', $(window).width() / 10  );
	  $("#selectItem").css('top', $(window).height() / 2);
	 }else{
	  $("#selectItem").css('display', 'none');
	 }
	}
	
	/* 鼠标拖动 */
var oDrag = "";
var ox,oy,nx,ny,dy,dx;
function drag(e,o){
 var e = e ? e : event;
 var mouseD = document.all ? 1 : 0;
 if(e.button == mouseD){
  oDrag = o.parentNode;
  ox = e.clientX;
  oy = e.clientY;  
 }
}
function dragPro(e){
 if(oDrag != ""){ 
  var e = e ? e : event;
  dx = parseInt($(oDrag).position().left);
  dy = parseInt($(oDrag).position().top);
  nx = e.clientX;
  ny = e.clientY;
  $(oDrag).css('left',(dx + ( nx - ox )) + "px" ) ;
  $(oDrag).css('top',(dy + ( ny - oy )) + "px" ) ;
  ox = nx;
  oy = ny;
 }
}
document.onmouseup = function(){oDrag = "";}
document.onmousemove = function(event){dragPro(event);}


function showSelect(id){
 for(var i = 0 ; i < grow ;i++){
  $("#c0" + i).css('display', 'none');
 }
 $("#c0" + id).css('display', 'block');
 showGrow = id;
}
function open(id,state){ //显示隐藏控制
 if(state == 1)
 	$(id).css('display', 'block');
 $(id).css('display', 'none');
}
function addPreItem(  ){
 
 $("#previewItem").html(""); 
 var mes = "" ; 
 for(var i = 0 ; i < items.length ; i++){
  if(items[i].checked == true){
	   mes += "<input type='checkbox' checked='true' value='"+ items[i].value +"' onclick='copyItem(\"#previewItem\",\"#previewItem\");same(this);'>" + items[i].value.split(":")[1];
	   $("#previewItem").html( mes ); 
   }
  }
 }


function makeSure(){
 openBg(0);
 openSelect(0);
 var selectItems = $("#previewItem").find("input");
 var values = "" ;
 for( var i = 0 ; i < selectItems.length ; i++ ){
	 if(selectItems[i].checked == true){
		 if( values == "" ){
			 values +=  selectItems[i].value.split(":")[0];
		 }else{
			values += ","+  selectItems[i].value.split(":")[0];
		 }
	 }
 }
 $.ajax({
   type: "POST",
   url: "sys/getSoftwareItemSummaryByPhoneModelIds.do",
   data: "ids="+values ,
   success: function(msg){
	 $("#phoneModelIds").val(values);
     $("#softwareItemSummary").val(msg);
   }
 });
 //alert(values);
 //copyItem("#previewItem","#makeSureItem") 
}
function copyHTML(id1,id2){
 $(id2).html( $("#id1").html() );
}
function copyItem(id1,id2){
 var mes = "";
 var items2 = $(id1).find("input");

 for(var i = 0 ; i < items2.length ; i++) {
  if(items2[i].checked == true) {
   mes += "<input type='checkbox' checked='true' value='"+ items2[i].value +"' onclick='copyItem(\"" + id2+ "\",\""+ id1 +"\");same(this);'>" + items2[i].value.split(":")[1];   
   $(id2).html(mes);
  }
 }
 
 if( items2.length == 1 ){
	 if(items2[0].checked != true) {
		 $(id2).html("");
	 }
 }
}
function same(ck){
 for(var i = 0 ; i < items.length ; i++) {
  if(ck.value == items[i].value) {
   items[i].checked = ck.checked;
  }
 }
} 

var grow = $("#selectSub").find("select option").length; //组数
var showGrow = 0;//已打开组
var selectCount = 0; //已选数量 
showSelect(showGrow);
var items = $("#selectSub").find("input");